import { ethers } from "ethers";
const ALCHEMY_MAINNET_URL = 'https://eth-mainnet.g.alchemy.com/v2/mkM5-GVJCs00ghRsjT7aU';
// 连接主网 provider
const provider = new ethers.JsonRpcProvider(ALCHEMY_MAINNET_URL);

// 利用助记词创建钱包
const wallet = ethers.Wallet.fromPhrase('magnet genuine custom runway vessel misery monkey kite chat diary habit decide', provider)

// DAI的ABI
const abiDAI = [
    "function balanceOf(address) public view returns(uint)",
    "function transfer(address, uint) public returns (bool)",
];

// DAI合约地址（主网）
const addressDAI = '0x6B175474E89094C44Da98b954EedeAC495271d0F' // DAI Contract
// 创建DAI合约实例
const contractDAI = new ethers.Contract(addressDAI, abiDAI, provider)

const address = wallet.getAddress()
const balanceDAI = await contractDAI.balanceOf("0x0c903235c380A717D970Bbf91f4dd5780fd68CEB")
console.log(ethers.formatEther(balanceDAI))

// 模拟转账 有余额即为true
const tx = await contractDAI.transfer.staticCall(address, ethers.parseEther("1"), {from : "0x0c903235c380A717D970Bbf91f4dd5780fd68CEB"})
console.log(`交易会成功吗？：`, tx)

